package org.czy.kafka.test.interceptor;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * MyInterceptor
 *
 * @author caizhiyang
 * @since 2024-04-25
 */
public class MyInterceptor implements ProducerInterceptor<String,String> {

    @Override
    //发送数据会调用此方法
    public ProducerRecord<String, String> onSend(ProducerRecord<String, String> record) {
        return new ProducerRecord<>(record.topic(), record.key(),record.value()+record.value());
    }

    @Override
    //发送数据完毕,服务器返回响应,会调用此方法
    public void onAcknowledgement(RecordMetadata metadata, Exception exception) {

    }

    @Override
    //生产者对象close时会调用此方法
    public void close() {

    }

    @Override
    //创建生产者对象时调用
    public void configure(Map<String, ?> configs) {

    }
}
